package com.mingnew.ecache.config;

import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author : lk
 * @date 2021/5/2 0:27
 **/
@Configuration
@EnableSwagger2
public class Swagger2Config {

    @Bean
    @Primary
    public Docket createApiDocket() {

        Docket docket = new Docket(DocumentationType.SWAGGER_2);
        docket
                .apiInfo(apiInfo())
                .enable(true)
                .groupName("第一个模块")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.mingnew.ecache.controller"))
                .paths(PathSelectors.any())
                .build();
        return docket;
    }



    @Bean
    public Docket restApi2() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("其他接口")
                .apiInfo(apiInfo())
                .useDefaultResponseMessages(true)
                .forCodeGeneration(true)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.mingnew.ecache.test.controller"))
                .paths(PathSelectors.regex("/other.*"))
                .build();
    }

    private ApiInfo apiInfo() {
        ApiInfo build = new ApiInfoBuilder().version("1.0")
                .title("明牛云科技有限公司")
                .description("明牛云科技有限公司api文档")
                .contact(new Contact("mingnew", "http://mingnew.com", "无"))
                .termsOfServiceUrl("http://mingnew.com")
                .build();
        return build;
    }
}
